package com.sims.daoImp;

import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.sims.bean.EfileVolunteer;
import com.sims.dao.IEfileVolunteerDAO;

/**
 * A data access object (DAO) providing persistence and search support for
 * EfileVolunteer entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.sims.bean.EfileVolunteer
 * @author MyEclipse Persistence Tools
 */

public class EfileVolunteerDAO extends HibernateDaoSupport implements IEfileVolunteerDAO {
	private static final Logger log = LoggerFactory
			.getLogger(EfileVolunteerDAO.class);
	// property constants
	public static final String SID = "sid";
	public static final String VRANK = "vrank";
	public static final String VSCHOOL = "vschool";
	public static final String SPECIALTY = "specialty";

	@Override
	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#save(com.sims.bean.EfileVolunteer)
	 */
	@Override
	public void save(EfileVolunteer transientInstance) {
		log.debug("saving EfileVolunteer instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#delete(com.sims.bean.EfileVolunteer)
	 */
	@Override
	public void delete(EfileVolunteer persistentInstance) {
		log.debug("deleting EfileVolunteer instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#findById(java.lang.Integer)
	 */
	@Override
	public EfileVolunteer findById(java.lang.Integer id) {
		log.debug("getting EfileVolunteer instance with id: " + id);
		try {
			EfileVolunteer instance = (EfileVolunteer) getHibernateTemplate()
					.get("com.sims.bean.EfileVolunteer", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#findByExample(com.sims.bean.EfileVolunteer)
	 */
	@Override
	public List findByExample(EfileVolunteer instance) {
		log.debug("finding EfileVolunteer instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#findByProperty(java.lang.String, java.lang.Object)
	 */
	@Override
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding EfileVolunteer instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from EfileVolunteer as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#findBySid(java.lang.Object)
	 */
	@Override
	public List findBySid(Object sid) {
		return findByProperty(SID, sid);
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#findByVrank(java.lang.Object)
	 */
	@Override
	public List findByVrank(Object vrank) {
		return findByProperty(VRANK, vrank);
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#findByVschool(java.lang.Object)
	 */
	@Override
	public List findByVschool(Object vschool) {
		return findByProperty(VSCHOOL, vschool);
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#findBySpecialty(java.lang.Object)
	 */
	@Override
	public List findBySpecialty(Object specialty) {
		return findByProperty(SPECIALTY, specialty);
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#findAll()
	 */
	@Override
	public List findAll() {
		log.debug("finding all EfileVolunteer instances");
		try {
			String queryString = "from EfileVolunteer";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#merge(com.sims.bean.EfileVolunteer)
	 */
	@Override
	public EfileVolunteer merge(EfileVolunteer detachedInstance) {
		log.debug("merging EfileVolunteer instance");
		try {
			EfileVolunteer result = getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#attachDirty(com.sims.bean.EfileVolunteer)
	 */
	@Override
	public void attachDirty(EfileVolunteer instance) {
		log.debug("attaching dirty EfileVolunteer instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.sims.daoImp.IEfileVolunteerDAO#attachClean(com.sims.bean.EfileVolunteer)
	 */
	@Override
	public void attachClean(EfileVolunteer instance) {
		log.debug("attaching clean EfileVolunteer instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static IEfileVolunteerDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (IEfileVolunteerDAO) ctx.getBean("EfileVolunteerDAO");
	}
}